package com.yuanyi.contract.demo.service.impl;

import com.codingapi.tx.annotation.ITxTransaction;
import com.yuanyi.contract.demo.dao.TestMapper;
import com.yuanyi.contract.demo.entity.Test;
import com.yuanyi.contract.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by lorne on 2017/6/26.
 */
@Service
public class DemoServiceImpl implements DemoService,ITxTransaction{

    @Autowired
    private TestMapper testMapper;



    @Override
    public List<Test> list() {
        return testMapper.findAll();
    }


    @Override
    @Transactional
    public int save() {
        //throw new RuntimeException("抛错了!");
        try {
            Thread.sleep(10000);
            int rs = testMapper.save("mybatis-hello-2");
            System.out.println("11111111111111111111111111111111111111111111111111");
            return rs;
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return 0;


    }
}
